﻿/**
 * ...
 * @author krozalski
 */

package hapi.math;

class Angle implements Additive<Angle, Angle>, implements Multiplicative<Angle, Float> {

	public var radians(default,null):Float;
	public var degrees(getDegrees, never):Float;
	
	public function new(radians:Float) {
		setRadians(radians);
	}
	
	public function add(angle:Angle):Angle {
		setRadians(this.radians + angle.radians);
		return this;
	}
	
	public function substract(angle:Angle):Angle {
		setRadians(this.radians - angle.radians);
		return this;
	}
	
	public function multiplyBy(v:Float):Angle {
		setRadians(this.radians * v);
		return this;
	}
	
	public function divideBy(v:Float):Angle {
		setRadians(this.radians/v);
		return this;
	}
	
	public function isZero():Bool {
		return radians == 0.0;
	}
	
	public function clone():Angle {
		return new Angle(radians);
	}
	
	inline function setRadians(rad) {
		this.radians = MathUtil.minimaizeAngle(rad);
	}
	
	function getDegrees() {
		return MathUtil.radToDeg(radians);
	}
	
	public function toString():String {
		return degrees + " degrees";
	}
}